import React, { Component } from 'react';
import { base,toast} from 'nc-lightapp-front';
const { NCModal, NCButton } = base;
const { Header: NCModalHeader, Body: NCModalBody, Footer: NCModalFooter } = NCModal;
import './index.less';

class QuerySettingsResults extends Component {
    constructor(props) {
        super(props);
        this.confirmModal = this.confirmModal.bind(this);
        this.closeModal = this.closeModal.bind(this);
        this.openModal = this.openModal.bind(this);
        this.state = {
            oldData:{},//上一次选中的数据
            language: {}
        }
    }
    componentDidMount() {
       
    }
    getLanguage (language) {
        this.setState({
            language: language
        })
    }
    confirmModal(){
        const { form, getManageScopeView, getQuerySettingsResultsOldData} = this.props;
        if (!form.getFormItemsValue('card2', 'bu').value && !form.getFormItemsValue('card2', 'dept').value && !form.getFormItemsValue('card2', 'job').value && !form.getFormItemsValue('card2', 'post').value && !form.getFormItemsValue('card2', 'psn').value && !form.getFormItemsValue('card2', 'target').display){
            toast({
                color: 'warning',
                content: this.state.language['hi6007-000265'] // 请至少输入一条除【管理业务】之外的查询条件
            }); 
        }else{
            getManageScopeView();
            this.closeModal();
            this.setState({
                oldData: form.getAllFormValue('card2')
            })
            getQuerySettingsResultsOldData(form.getAllFormValue('card2'));
            
        }
        
    }
    closeModal(){
        this.props.onClose && this.props.onClose();
    }
    openModal(){
        let meta = this.props.meta.getMeta();
        let psnJobItem = meta['card2'].items.find(item => item.attrcode === 'busiregion');
        psnJobItem.options = [
        {
            value: '',
            display: ''
        },{
            value: 'PSNDOC00000000000000',
            display: this.state.language['hi6007-000259'] // 人事管理
        },
        {
            value: 'PSNPACT0000000000000',
            display: this.state.language['hi6007-000260'] // 合同管理
        }, {
            value: 'SALARY00000000000000',
            display: this.state.language['hi6007-000261'] // 薪酬管理
        }]
        this.props.meta.setMeta(meta);
        if (this.state.oldData.rows) {
            this.props.form.setAllFormValue({
                'card2': this.state.oldData
            })
        }
    }
    render() {
        const {
            form
        } = this.props;
        const { createForm } = form;
        const { visible } = this.props;
    
        return (
            <NCModal
                show={visible}
                size="lg"
                className="query-settings-results"
                onHide={this.closeModal}
                backdrop={'static'}
                onEnter={this.openModal}
            >
                {/* 查询设置结果 */}
                <NCModalHeader closeButton={true}>
                    {this.state.language['hi6007-000266']}
                </NCModalHeader>
                <NCModalBody>
                    {
                        createForm('card2', {
                        
                        })
                    }

                </NCModalBody>
                <NCModalFooter>
                    <NCButton colors="primary" 
                        onClick={this.confirmModal}
                    >
                        {/* 确定 */}
                        {this.state.language['hi6007-000004']}
                        </NCButton>
                    <NCButton
                        shape="border"
                        onClick={this.closeModal}
                    >
                        {/* 取消 */}
                        {this.state.language['hi6007-000005']}
                    </NCButton>
                </NCModalFooter>
            </NCModal>
        );
    }
}

export default QuerySettingsResults;
